home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 131 / XENIATGM131.iso / Shareware / openOffice.org 641 / Windows / f_0266 / Hard.xba < prev    next >
Extensible Markup Language  |  2001-10-31  |  8KB  |  234 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Hard" script:language="StarBasic">REM  *****  BASIC  *****
  4. Option Explicit
  5. 'ToDo: W├â┬ñhrung wechseln und dann sehen, ob die Listbox mit den neuen Ranges aufgefrischt wird
  6.  
  7.  
  8. Sub CreateRangeList()
  9. Dim MaxIndex as Integer
  10.     MaxIndex = -1
  11.     EnableStep1DialogControls(False, False, False)
  12.     EmptySelection()
  13.     DialogModel.lblSelection.Label = sCURRRANGES      '"W├ñhrungsbereiche:"
  14.     EmptyListbox(DialogModel.lstSelection)
  15.     oDocument.CurrentController.Select(oSelRanges)
  16.     If (DialogModel.optSheetRanges.State = 1) AND (DialogModel.chkComplete.State <> 1) Then
  17.         ' Ist das Sheet Grundlage f├╝r die Bearbeitung?
  18.         oStatusline.SetText(sStsRELRANGES)                '"Erfassung der relevanten Bereiche..."
  19.         osheet = oDocument.CurrentController.GetActiveSheet
  20.         oRanges = osheet.CellFormatRanges.createEnumeration()
  21.         MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, False)
  22.         If MaxIndex > -1 Then
  23.             ReDim Preserve RangeList(MaxIndex,1)
  24.         End If
  25.     Else
  26.         CreateRangeEnumeration(False)
  27.         bRangeListDefined = True
  28.     End If
  29.     EnableStep1DialogControls(True, True, True)
  30.     oStatusline.SetText("")
  31. End Sub
  32.  
  33.  
  34. Sub CreateRangeEnumeration(bAutopilot as Boolean)
  35. Dim i as Integer
  36. Dim MaxIndex as integer
  37. Dim sStatustext as String
  38.     MaxIndex = -1
  39.     If Not bRangeListDefined Then
  40.         ' Die Ranges sind noch nicht definiert
  41.         oSheets = oDocument.Sheets
  42.         For i = 0 To oSheets.Count-1
  43.             oSheet = oSheets.GetbyIndex(i)
  44.             If bAutopilot Then
  45.                 IncreaseStatusValue(SBRELGET/osheets.Count)
  46.             Else
  47.                 sStatustext = ReplaceString(sStsRELSHEETRANGES,Str(i+1),"%1Number%1")
  48.                 sStatustext = ReplaceString(sStatusText,oSheets.Count,"%2TotPageCount%2")
  49.                 oStatusline.SetText(sStatusText)
  50.             End If
  51.             oRanges = osheet.CellFormatRanges.createEnumeration
  52.             MaxIndex = AddSheetRanges(oRanges, MaxIndex, oSheet, bAutopilot)
  53.         Next i
  54.     Else
  55.         If Not bAutoPilot Then
  56.             oStatusline.SetText(sStsRELRANGES)      '"Erfassung der relevanten Bereiche..."
  57.             ' Die Ranges sind schon definiert
  58.             For i = 0 To Ubound(RangeList(),1)
  59.                 If RangeList(i,0) <> "" AND Rangelist(i,1) = True Then
  60.                     AddSingleItemToListBox(DialogModel.lstSelection, RangeList(i))
  61.                 End If
  62.             Next
  63.         End If
  64.     End If
  65.     If MaxIndex > -1 Then
  66.         ReDim Preserve RangeList(MaxIndex,1)
  67. '    Else
  68. '        ReDim RangeList(,1)
  69.     End If
  70.     Rangeindex = MaxIndex
  71. End Sub
  72.     
  73.     
  74. Function AddSheetRanges(oRanges as Object, r as Integer, oSheet as Object, bAutopilot)
  75. Dim RangeName as String
  76. Dim AddtoList as Boolean
  77. Dim iCurStep as Integer
  78. Dim MaxIndex as Integer
  79.     iCurStep = DialogModel.Step
  80.     While oRanges.hasMoreElements
  81.         oRange = oRanges.NextElement
  82.         AddToList = CheckFormatType(oRange)
  83.         If AddToList Then
  84.             RangeName = RetrieveRangeNamefromAddress(oRange)
  85.             TotCellCount = TotCellCount + CountRangeCells(oRange)
  86.             If Not bAutoPilot Then
  87.                 AddSingleItemToListbox(DialogModel.lstSelection, RangeName)
  88.             End If
  89.             ' The Ranges are only passed to an Array when the whole Document is the basis
  90.             ' Redimension the RangeList Array if necessary
  91.             MaxIndex = Ubound(RangeList(),1)
  92.             r = r + 1
  93.             If r > MaxIndex Then
  94.                 MaxIndex = MaxIndex + SBRANGEUBOUND
  95.                 ReDim Preserve RangeList(MaxIndex,1)
  96.             End If
  97.             RangeList(r,0) = RangeName
  98.             RangeList(r,1) = True
  99.         End If
  100.     Wend
  101.     AddSheetRanges = r
  102. End Function
  103.  
  104.  
  105. ' F├╝gt einen Bereich zur selektierten Kollektion hinzu
  106. Sub SelectRange()
  107. Dim i as Integer
  108. Dim RangeName as String
  109. Dim SelItem as String
  110. Dim CurRange as String
  111. Dim SheetRangeName as String
  112. Dim DescriptionList() as String
  113. Dim MaxRangeIndex as Integer
  114. Dim StatusValue as Integer
  115.     StatusValue = 0
  116.     MaxRangeIndex = Ubound(SelRangeList())
  117.     CurSheetName = oSheet.Name
  118.     For i = 0 To MaxRangeIndex
  119.         SelItem = SelRangeList(i)
  120.         ' Is the Range already included in the collection?
  121.         oRange = RetrieveRangeoutOfRangename(SelItem)
  122.         TotCellCount = TotCellCount + CountRangeCells(oRange)
  123.         DescriptionList() = ArrayOutofString(SelItem,".",1)
  124.         SheetRangeName = DeleteStr(DescriptionList(0),"'")
  125.         If SheetRangeName = CurSheetName Then
  126.             oSelRanges.InsertbyName("",oRange)
  127.         End If
  128.         IncreaseStatusValue(SBRELGET/MaxRangeIndex)
  129.     Next i
  130. End Sub
  131.  
  132.  
  133. Sub ConvertThehardWay(ListboxList(), SwitchFormat as Boolean, bRemove as Boolean)
  134. Dim i as Integer ' r, a
  135. Dim AddCells as Long
  136. Dim OldStatusValue as Single
  137. Dim RangeName as String
  138. Dim LastIndex as Integer
  139. Dim oSelListbox as Object
  140.  
  141.     oSelListbox = DialogConvert.GetControl("lstSelection")
  142.     Lastindex = Ubound(ListboxList())
  143.     If TotCellCount > 0 Then
  144.         OldStatusValue = StatusValue
  145.         ' Harte Formatierung
  146.         For i = 0 To LastIndex
  147.             RangeName = ListboxList(i)
  148.             oRange = RetrieveRangeoutofRangeName(RangeName)
  149.             ConvertCellCurrencies(oRange)
  150.             If bRemove Then
  151.                 If oSelRanges.HasbyName(RangeName) Then
  152.                     oSelRanges.RemovebyName(RangeName)
  153.                     oDocument.CurrentController.Select(oSelRanges)    
  154.                 End If
  155.             End If
  156.             If SwitchFormat Then
  157.                 If oRange.getPropertyState("NumberFormat") <> 1 Then
  158.                     ' Range Ist hart formatiert
  159.                     SwitchNumberFormat(oRange, oFormats, sEuroSign)' "Γé¼")
  160.                 End If
  161.             Else
  162.                 SwitchNumberFormat(oRange, oFormats, sEuroSign) '"Γé¼"
  163.             End If
  164.             AddCells = CountRangeCells(oRange)
  165.             CurCellCount = AddCells
  166.             IncreaseStatusValue((CurCellCount/TotCellCount)*(100-OldStatusValue))
  167.             If bRemove Then
  168.                 RemoveListBoxItemByName(oSelListbox.Model,Rangename)
  169.             End If
  170.         Next
  171.     End If
  172. End Sub
  173.  
  174.  
  175. Sub ConvertCellCurrencies(oRange as Object)
  176. Dim oValues as Object
  177. Dim oCells as Object
  178. Dim oCell as Object
  179.       oValues = oRange.queryContentCells(com.sun.star.sheet.CellFlags.VALUE)
  180.     If (oValues.Count > 0) Then
  181.         oCells = oValues.Cells.createEnumeration
  182.         While oCells.hasMoreElements
  183.             oCell = oCells.nextElement
  184.             ModifyObjectValuewithCurrFactor(oCell)
  185.         Wend
  186.     End If
  187. End Sub
  188.  
  189.  
  190. Sub ModifyObjectValuewithCurrFactor(oDocObject as Object)
  191. Dim oDocObjectValue as double
  192.     oDocObjectValue = oDocObject.Value
  193.     oDocObject.Value = Round(oDocObjectValue/CurrFactor, 2)
  194. End Sub
  195.  
  196.  
  197. Function CheckIfRangeisCurrency(FormatObject as Object)
  198. Dim oFormatofObject() as Object
  199.     ' Retrieve the Format of the Object
  200.     On Local Error GoTo NOKEY
  201.     oFormatofObject() = oFormats.getByKey(FormatObject.NumberFormat)
  202.     On Local Error GoTo 0            
  203.  
  204.     ' Typ und W├ñhrungssymbol des Numberformats heraussuchen
  205.     ' Todo: ├£berpr├╝fe, ob diese beiden Zeilen nicht eleganter gehen
  206.      CheckIfRangeIsCurrency = INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY
  207.     Exit Function
  208. NOKEY:
  209.     CheckIfRangeisCurrency = False
  210.     Resume CLERROR
  211.     CLERROR:
  212. End Function
  213.  
  214.  
  215. Function CountColumnsForRow(IndexArray() as String, Row as Integer)
  216. Dim i as Integer
  217. Dim NoNulls as Boolean
  218.     For i = 1 To Ubound(IndexArray,2)
  219.         If IndexArray(Row,i)= "" Then
  220.             NoNulls = False
  221.             Exit For
  222.         End If
  223.     Next
  224.     CountColumnsForRow = i
  225. End Function
  226.  
  227.  
  228. Function CountRangeCells(oRange as Object) As Long
  229. Dim oRangeAddress as Object
  230. Dim LocCellCount as Long
  231.     oRangeAddress = oRange.RangeAddress
  232.     LocCellCount = (oRangeAddress.EndColumn - oRangeAddress.StartColumn + 1) * (oRangeAddress.EndRow - oRangeAddress.StartRow + 1)
  233.     CountRangeCells = LocCellCount
  234. End Function</script:module>